package com.ruoyi.project.system.wxnotice.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.system.wxnotice.domain.WxNotice;
import com.ruoyi.project.system.wxnotice.service.IWxNoticeService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 通知Controller
 * 
 * @author ruoyi
 * @date 2021-05-24
 */
@Controller
@RequestMapping("/system/wxnotice")
public class WxNoticeController extends BaseController
{
    private String prefix = "system/wxnotice";

    @Autowired
    private IWxNoticeService wxNoticeService;

    @RequiresPermissions("system:wxnotice:view")
    @GetMapping()
    public String wxnotice()
    {
        return prefix + "/wxnotice";
    }

    /**
     * 查询通知列表
     */
    @RequiresPermissions("system:wxnotice:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(WxNotice wxNotice)
    {
        startPage();
        List<WxNotice> list = wxNoticeService.selectWxNoticeList(wxNotice);
        return getDataTable(list);
    }

    /**
     * 导出通知列表
     */
    @RequiresPermissions("system:wxnotice:export")
    @Log(title = "通知", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(WxNotice wxNotice)
    {
        List<WxNotice> list = wxNoticeService.selectWxNoticeList(wxNotice);
        ExcelUtil<WxNotice> util = new ExcelUtil<WxNotice>(WxNotice.class);
        return util.exportExcel(list, "通知数据");
    }

    /**
     * 新增通知
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存通知
     */
    @RequiresPermissions("system:wxnotice:add")
    @Log(title = "通知", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(WxNotice wxNotice)
    {
        return toAjax(wxNoticeService.insertWxNotice(wxNotice));
    }

    /**
     * 修改通知
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        WxNotice wxNotice = wxNoticeService.selectWxNoticeById(id);
        mmap.put("wxNotice", wxNotice);
        return prefix + "/edit";
    }

    /**
     * 修改保存通知
     */
    @RequiresPermissions("system:wxnotice:edit")
    @Log(title = "通知", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(WxNotice wxNotice)
    {
        return toAjax(wxNoticeService.updateWxNotice(wxNotice));
    }

    /**
     * 删除通知
     */
    @RequiresPermissions("system:wxnotice:remove")
    @Log(title = "通知", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(wxNoticeService.deleteWxNoticeByIds(ids));
    }
}
